//
//  CustomGuideView.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/10/17.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CustomGuideView.h"

@interface CustomGuideView()<UIScrollViewDelegate>

@property(nonatomic,strong)UIPageControl *pageControl;
@property(nonatomic,strong)UIView *bottomLeftView;
@property(nonatomic,strong)UIView *bottomRightView;
@property(nonatomic,strong)UIView *bottomCenterView;
@end
@implementation CustomGuideView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];
        [self addSubview:scrollView];
        scrollView.delegate = self;
        scrollView.showsVerticalScrollIndicator = NO;
        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.contentSize = CGSizeMake(WIDTH * 3, HEIGHT);
        scrollView.pagingEnabled = YES;
        for (NSInteger i = 0; i < 3; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * WIDTH, 0, WIDTH, HEIGHT)];
            imageView.userInteractionEnabled = YES;
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"引导页%ld.jpg",(long)i + 1]];
            [scrollView addSubview:imageView];
        }
                [self addSubViewInScrollView];
        NSLog(@"什么东西");
    }
    return self;
}
-(void)addSubViewInScrollView{
    self.bottomLeftView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH/2 - 40, HEIGHT - 60, 40, 10)];
    self.bottomLeftView.backgroundColor = COLOR_HEX(0xF2D04F);
    self.bottomLeftView.layer.cornerRadius = 5;
    self.bottomLeftView.layer.masksToBounds = YES;
    
    self.bottomCenterView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH/2 + 10, HEIGHT - 60, 10, 10)];
    self.bottomCenterView.backgroundColor = [UIColor whiteColor];
    self.bottomCenterView.layer.cornerRadius = 5;
    self.bottomCenterView.layer.masksToBounds = YES;
    
    self.bottomRightView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH/2 + 30, HEIGHT - 60, 10, 10)];
    self.bottomRightView.backgroundColor = [UIColor whiteColor];
    self.bottomRightView.layer.cornerRadius = 5;
    self.bottomRightView.layer.masksToBounds = YES;
    [self addSubview:_bottomLeftView];
    [self addSubview:_bottomRightView];
    [self addSubview:_bottomCenterView];
    [self bringSubviewToFront:_bottomRightView];
    [self bringSubviewToFront:_bottomLeftView];
    [self bringSubviewToFront:_bottomCenterView];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x > WIDTH * 2 + 30) {
        NSLog(@"sousou");
        self.closeAndInBlock();
    }
    if (scrollView.contentOffset.x < WIDTH) {
        [UIView animateWithDuration:0.5 animations:^{
            self.bottomLeftView.frame = CGRectMake(WIDTH/2 - 40, HEIGHT - 60, 40, 10);
            self.bottomCenterView.frame = CGRectMake(WIDTH/2 + 10, HEIGHT - 60, 10, 10);
            self.bottomRightView.frame = CGRectMake(WIDTH/2 + 30, HEIGHT - 60, 10, 10);
            self.bottomCenterView.backgroundColor = [UIColor whiteColor];
            self.bottomLeftView.backgroundColor = COLOR_HEX(0xF2D04F);
            self.bottomRightView.backgroundColor = [UIColor whiteColor];
        }];
    }
    if (scrollView.contentOffset.x >= WIDTH) {
        [UIView animateWithDuration:0.5 animations:^{
            self.bottomLeftView.frame = CGRectMake(WIDTH/2 - 40, HEIGHT - 60, 10, 10);
            self.bottomCenterView.frame = CGRectMake(WIDTH/2 - 20, HEIGHT - 60, 40, 10);
            self.bottomRightView.frame = CGRectMake(WIDTH/2 + 30, HEIGHT - 60, 10, 10);
             self.bottomLeftView.backgroundColor = [UIColor whiteColor];
            self.bottomRightView.backgroundColor = [UIColor whiteColor];
            self.bottomCenterView.backgroundColor = COLOR_HEX(0xF2D04F);
        }];
    }
    if (scrollView.contentOffset.x >= WIDTH * 2) {
        [UIView animateWithDuration:0.5 animations:^{
            self.bottomLeftView.frame = CGRectMake(WIDTH/2 - 40, HEIGHT - 60, 10, 10);
            self.bottomCenterView.frame = CGRectMake(WIDTH/2 - 20, HEIGHT - 60, 10, 10);
            self.bottomRightView.frame = CGRectMake(WIDTH/2, HEIGHT - 60, 40, 10);
            self.bottomLeftView.backgroundColor = [UIColor whiteColor];
            self.bottomRightView.backgroundColor = COLOR_HEX(0xF2D04F);
            self.bottomCenterView.backgroundColor = [UIColor whiteColor];
        }];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
